﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

class StartGameScreen : MenuScreen
{
    SpriteFont font;
    
    private Texture2D backgroundTexture;
    private Vector2 backgroundPosition;

    MenuEntry newGameEntry, passwordEntry, goToPreviousEntry;

    private Texture2D buttonNewGameSelectedTexture, buttonPasswordSelectedTexture, buttonBackSelected;

    public StartGameScreen()
        : base()
    {
        Direction = MenuEntryDirection.STARTGAME;

        newGameEntry = new MenuEntry("");
        newGameEntry.Description = "Start a new Game";
        newGameEntry.Position = new Vector2(000, 000f);
        newGameEntry.Selected += NewGameMenuEntrySelected;
        MenuEntries.Add(newGameEntry);

        passwordEntry = new MenuEntry("");
        passwordEntry.Description = "Put a password to start in an other level";
        passwordEntry.Position = new Vector2(640, 0);
        passwordEntry.Selected += PasswordEntrySelected;
        //MenuEntries.Add(passwordEntry);

        goToPreviousEntry = new MenuEntry("");
        goToPreviousEntry.Description = "Return to Main Menu";
        goToPreviousEntry.Position = new Vector2(290, 320);
        goToPreviousEntry.Selected += OnCancel;
        MenuEntries.Add(goToPreviousEntry);
    }

    /// <summary>
    /// Load the graphics content for this screen.
    /// </summary>
    public override void LoadContent()
    {
        // load the textures
        ContentManager content = ScreenManager.Game.Content;

        font = content.Load<SpriteFont>("SpriteFont1");

        //set font on each entry menu
        newGameEntry.Font = font;
        passwordEntry.Font = font;
        goToPreviousEntry.Font = font;

        backgroundTexture = content.Load<Texture2D>(@"Textures\MenuMock\Menu_PasswordCinza2");
        buttonNewGameSelectedTexture = content.Load<Texture2D>(@"Textures\MenuMock\menu_newgame");
        buttonPasswordSelectedTexture = content.Load<Texture2D>(@"Textures\MenuMock\menu_Passwordbotao");
        buttonBackSelected = content.Load<Texture2D>(@"Textures\MenuMock\manu_back");

        // calculate the texture positions
        Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
        backgroundPosition = new Vector2(
            (viewport.Width - backgroundTexture.Width) / 2,
            (viewport.Height - backgroundTexture.Height) / 2);

        // set the textures on each menu entry
        newGameEntry.SelectedTexture = buttonNewGameSelectedTexture;

        passwordEntry.SelectedTexture = buttonPasswordSelectedTexture;

        goToPreviousEntry.SelectedTexture = buttonBackSelected;

        base.LoadContent();
    }

    public override void HandleInput()
    {
        if (InputManager.IsActionTriggered(InputManager.Action.Back))
        {
            ExitScreen();
            return;
        }

        base.HandleInput();
    }

    void NewGameMenuEntrySelected(object sender, EventArgs e)
    {
        ScreenManager.AddScreen(new CharacterChooseScreen());
    }

    void PasswordEntrySelected(object sender, EventArgs e)
    {
        ScreenManager.AddScreen(new PasswordScreen());
    }

    public override void Draw(GameTime gameTime)
    {
        SpriteBatch spriteBatch = ScreenManager.SpriteBatch;

        spriteBatch.Begin();

        // draw the background images
        spriteBatch.Draw(backgroundTexture, backgroundPosition, Color.White);

        // Draw each menu entry in turn.
        for (int i = 0; i < MenuEntries.Count; i++)
        {
            MenuEntry menuEntry = MenuEntries[i];
            bool isSelected = IsActive && (i == selectedEntry);
            menuEntry.Draw(this, isSelected, gameTime);
        }

        spriteBatch.End();
    }

}
